#include "DialSW.h"


//下位机版本保存的变量
static uint8_t DialSW_PCBVersion	=	0;

//拨码开关初始化

/***********************
*函数名称：DIALSW_Configuration
*函数功能：拨码开关初始化
*输入参数：none
*输出参数：none
**************************/
void DIALSW_Configuration(void)
{
	//定义变量
    GPIO_InitTypeDef GPIO_InitStructure;		
	//开启RCC
	switch((uint32_t)SW_PORT_1)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)SW_PORT_2)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}
	switch((uint32_t)SW_PORT_3)
	{
		case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);break;
		case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);break;
		case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);break;
		case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);break;
		case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);break;	
		case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);break;
	}	
	//设置IO
    GPIO_InitStructure.GPIO_Pin		=	SW_PIN_1;           
    GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_IN_FLOATING;				//输入浮空
    GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;         
    GPIO_Init(SW_PORT_1, &GPIO_InitStructure);  
	
    GPIO_InitStructure.GPIO_Pin		=	SW_PIN_2;           
    GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_IN_FLOATING;				//输入浮空
    GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;         
    GPIO_Init(SW_PORT_2, &GPIO_InitStructure);
	
    GPIO_InitStructure.GPIO_Pin		=	SW_PIN_3;           
    GPIO_InitStructure.GPIO_Mode 	= 	GPIO_Mode_IN_FLOATING;				//输入浮空
    GPIO_InitStructure.GPIO_Speed 	= 	GPIO_Speed_50MHz;         
    GPIO_Init(SW_PORT_3, &GPIO_InitStructure);	
	//获取下位机PCB版本
	DialSW_PCBVersion	=	0;
	if(GPIO_ReadInputDataBit(SW_PORT_1,SW_PIN_1))
		DialSW_PCBVersion	|=	(1 << 0);
	else
		DialSW_PCBVersion	&=	~(1 << 0);
	
	if(GPIO_ReadInputDataBit(SW_PORT_2,SW_PIN_2))
		DialSW_PCBVersion	|=	(1 << 1);
	else
		DialSW_PCBVersion	&=	~(1 << 1);	

	if(GPIO_ReadInputDataBit(SW_PORT_3,SW_PIN_3))
		DialSW_PCBVersion	|=	(1 << 2);
	else
		DialSW_PCBVersion	&=	~(1 << 2);	
}


//获取PCB版本
uint8_t DIALSW_GetPCBVersion(void)
{
	return DialSW_PCBVersion;
}
